import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/site/site_observer_list/views/site_observer_list_item_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';

///
/// @Description TODO
/// @Author liuer
/// @CreateTime 2024年05月17日 09:37
class DynamicMonitorWidget extends StatelessWidget {
  final Map map;
  final int index;
  final Function(List<dynamic>? dataList, int type)tapEditHandler;
  final Function()? editClick;
  const DynamicMonitorWidget(this.map,this.index,this.tapEditHandler,{this.editClick,super.key});

  @override
  Widget build(BuildContext context) {
    Log.d('map===' + map.toString());
    Widget widget = Container();
    String title1 = '';
    String title2 = '';
    String title3 = '';
    if (index == 3 || index == 4) {
      if (index == 3) {
        title1 = ResKey.siteSettingObserverChargePower.tr;
        title2 = ResKey.siteSettingObserverChargeRealTimePower.tr;
        // title1 = '充电桩充电量';
        // title2 = '充电桩实时功率';
      } else if (index == 4) {
        title1 = ResKey.siteSettingObserverLoadPower.tr;
        title2 = ResKey.siteSettingObserverLoadRealTimePower.tr;
        // title1 = '负载用电量';
        // title2 = '负载实时功率';
      }

      widget = Column(
        children: [
          SiteObserverListItemWidget(
            (map['valueMap'] != null && map['valueMap']['2'] != null) &&
                (map['flag'] == true)
                ? map['valueMap']['2']
                : [],
            map['flag'],
            title: title1,
            onItemTaped: (e) {
              tapEditHandler( (map['valueMap'] != null && map['valueMap']['2'] != null)
                  ? map['valueMap']['2']
                  : [],
                  2);
            },
          ),
          SiteObserverListItemWidget(
            (map['valueMap'] != null && map['valueMap']['4'] != null) &&
                (map['flag'] == true)
                ? map['valueMap']['4']
                : [],
            map['flag'],
            title: title2,
            onItemTaped: (e) {
              tapEditHandler(
                  (map['valueMap'] != null && map['valueMap']['4'] != null)
                      ? map['valueMap']['4']
                      : [],
                  4);
            },
          ),
        ],
      );
    } else {
      if (index == 0) {
        title1 = ResKey.siteSettingObserverElectricityConsumption.tr;
        title2 = ResKey.mainsFeederPower.tr;
        title3 = ResKey.siteSettingObserverElectricityPower.tr;
        // title1 = '市电用电量';
        // title2 = '市电功率';
      }else if (index == 1) {
        title1 = ResKey.siteSettingObserverPhotovoltaicQuantity.tr;
        title2 = ResKey.siteSettingObserverPhotovoltaicEnergy.tr;
        title3 = ResKey.siteSettingObserverPhotovoltaicPower.tr;
      } else if (index == 2) {
        title1 = ResKey.siteSettingObserverStoreChargePower.tr;
        title2 = ResKey.siteSettingObserverStoreDischargePower.tr;
        title3 = ResKey.siteSettingObserverStoreRealTimePower.tr;
      }
      widget = Column(
        children: [
          SiteObserverListItemWidget(
            (map['valueMap'] != null && map['valueMap']['2'] != null) &&
                (map['flag'] == true) &&
                (map['flag'] == true)
                ? map['valueMap']['2']
                : [],
            map['flag'],
            title: title1,
            onItemTaped: (e) {
              tapEditHandler(
                  (map['valueMap'] != null && map['valueMap']['2'] != null)
                      ? map['valueMap']['2']
                      : [],
                  2);
            },
            editClick: (){
              Log.d('editClick===');
              if(editClick !=null){
                editClick!();
              }

            },
          ),
          SiteObserverListItemWidget(
            (map['valueMap'] != null && map['valueMap']['3'] != null) &&
                (map['flag'] == true)
                ? map['valueMap']['3']
                : [],
            map['flag'],
            title: title2,
            onItemTaped: (e) {
              tapEditHandler(
                  (map['valueMap'] != null && map['valueMap']['3'] != null)
                      ? map['valueMap']['3']
                      : [],
                  3);
            }, editClick: (){
            Log.d('editClick===');
            if(editClick != null){
              editClick!();
            }
          },
          ),
          SiteObserverListItemWidget(
            (map['valueMap'] != null && map['valueMap']['4'] != null) &&
                (map['flag'] == true)
                ? map['valueMap']['4']
                : [],
            map['flag'],
            title: title3,
            onItemTaped: (e) {
              tapEditHandler(
                  (map['valueMap'] != null && map['valueMap']['4'] != null)
                      ? map['valueMap']['4']
                      : [],
                  4);
            }, editClick: (){
            Log.d('editClick===');
            if(editClick !=null){
              editClick!();
            }
          },
          ),
        ],
      );
    }
    return map['flag'] != null && map['flag'].toString() == 'true'?widget:Container();
  }
}
